<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true">
      <el-form-item label="配件品牌" prop="partBrand">
        <el-input
            v-model="queryParams.partBrand"
            placeholder="请输入配件品牌"
            clearable
            style="width: 200px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item label="配件名称" prop="partName">
        <el-input
            v-model="queryParams.partName"
            placeholder="请输入配件名称"
            clearable
            style="width: 200px"
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="noticeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="index" width="60" type="index"/>
      <el-table-column label="配件编号" align="center" prop="partNo"/>
      <el-table-column label="配件名称" align="center" prop="partName" show-overflow-tooltip/>
      <el-table-column label="配件品牌" align="center" prop="partBrand" show-overflow-tooltip/>
      <el-table-column label="配件型号" align="center" prop="partModel" show-overflow-tooltip/>
      <el-table-column label="配件数量" align="center" prop="partNum"/>
      <el-table-column label="单价" align="center" prop="partPrice"/>
      <el-table-column label="配件尺寸" align="center" prop="partSize" show-overflow-tooltip/>
    </el-table>
    <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.page"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>

<script setup name="Notice">
import { getAllPart } from "@/api/system/access.js"

const {proxy} = getCurrentInstance()

const noticeList = ref([])
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const loading = ref(true)
const total = ref(0)
const currentRow = ref()

const data = reactive({
  queryParams: {
    page: 1,
    pageSize: 10,
    partBrand: undefined,
    partName: undefined,
  }
})

const {queryParams} = toRefs(data)

/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.dictId)
  single.value = selection.length != 1
  currentRow.value = selection
  multiple.value = !selection.length
}

/** 查询公告列表 */
function getList() {
  loading.value = true
  getAllPart(queryParams.value).then(response => {
    noticeList.value = response.data.list
    total.value = response.data.total
    loading.value = false
  }).catch((err)=>{
    console.log(err)
    loading.value = false
  })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.page = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

//暴露给父组件的属性
defineExpose({currentRow})

getList()
</script>
